package com.qianyu.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianyu.project.core.context.user.FlowUserManager;
import com.qianyu.project.entity.SystemUser;
import com.qianyu.project.entity.TenderCompany;
import com.qianyu.project.mapper.TenderCompanyMapper;
import com.qianyu.project.service.ISystemUserService;
import com.qianyu.project.service.ITenderCompanyService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author gs
 * @date create in 2021/2/2 19:02
 */
@Service
public class TenderCompanyServiceImpl extends ServiceImpl<TenderCompanyMapper, TenderCompany> implements ITenderCompanyService {

    @Autowired
    private TenderCompanyMapper tenderCompanyMapper;
    @Autowired
    private FlowUserManager flowUserManager;
    @Autowired
    private ISystemUserService systemUserService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void register(TenderCompany tenderCompany) {
        //注册公司信息
        tenderCompanyMapper.insert(tenderCompany);
        //绑定到对应的用户上
        SystemUser systemUser = new SystemUser();
        systemUser.setId(flowUserManager.getFlowUser().getId());
        systemUser.setCompanyId(tenderCompany.getId());
        systemUserService.updateById(systemUser);
    }
}
